package x.y.z;

import java.util.Stack;

public class Interview_3_4_QueueViaStack {

}

class MyQueue {
    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        stackIn.push(x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        if (!stackOut.empty()) {
            return stackOut.pop();
        } else {
            while (!stackIn.empty()) {
                stackOut.push(stackIn.pop());
            }
            return stackOut.pop();
        }
    }

    /**
     * Get the front element.
     */
    public int peek() {
        if (!stackOut.empty()) {
            return stackOut.peek();
        } else {
            while (!stackIn.empty()) {
                stackOut.push(stackIn.pop());
            }
            return stackOut.peek();
        }
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return stackIn.empty() && stackOut.empty();
    }
}
